<template>
  <div class="area-container">
    <p class="area-title">
      <span>
        服务调用统计
      </span>

      <el-select
        v-model="value"
        size="small"
        clearable
        filterable
        placeholder="请选择服务"
        @change="getServiceCallDateNum"
      >
        <el-option
          v-for="(item, index) in interfaceList"
          :key="index"
          :label="item.serviceName"
          :value="item.id"
        />
      </el-select>
    </p>

    <!-- 饼状图 -->
    <div class="area-chart-container">
      <div ref="rightBottom" />
    </div>
  </div>
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from '@/framework/utils/mixins/resize'
import { getServiceCallDateNumApi } from '@/api/index'
export default {
  name: 'InterfacePlatformIndex',
  mixins: [resize],

  props: {
    interfaceList: {
      type: Array,
      default: () => []
    }
  },

  data() {
    return {
      projectList: [],
      value: '',
      chart: null
    }
  },

  mounted () {
    this.getServiceCallDateNum()
  },

  methods: {
    initChart (data) {
      if (this.chart) this.chart.clear()
      this.chart = echarts.init(this.$refs.rightBottom, 'macarons')
      const option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        grid: {
          left: '1%',
          right: '1%',
          bottom: '3%',
          top: '5%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          data: data.date
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            type: 'line',
            data: data.count
          }
        ]
      }
      this.chart.setOption(option)
    },

    getServiceCallDateNum () {
      getServiceCallDateNumApi({
        interfaceServiceId: this.value
      }).then(({ code, data }) => {
        if (code === '00000') {
          this.initChart(data)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.area-chart-container {
  height: calc(100% - 50px);
  & > div {
    height: 100%;
  }
}
</style>
